import cookie from '../../utils/cookies'
import api from '../../api/index'
export default {
    namespaced: true,
    state: {
        info: {},
        token: cookie.get('token') || ''
    },
    mutations: {
        SET_USET_INFO(state,payload) {
            state.info = payload;
        }
    },
    actions: {
        login({ dispatch }, payload) {
            return api.user.login(payload).then(() => {
                dispatch('getUserInfo')
            })
        },
        async getUserInfo({commit}) {
            const res = await api.user.info();
            commit('SET_USET_INFO', res.data)
        }
    }
}